package com.itheima.admin.controller;

import com.itheima.admin.pojo.User;
import com.itheima.admin.service.UserService;
import com.itheima.admin.util.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.Role;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
   //得到所有用户信息
    @GetMapping("/getAllUser/{currentPage}/{size}")
    public Result getAllUser(@PathVariable("currentPage") Integer currentPage,@PathVariable("size") Integer size){
        return userService.getAllUser(currentPage,size);
    }
   //添加用户
    @PostMapping("/addUser")
    public Result addUser(@RequestBody User user){
        return userService.insertUser(user);
    }
   //删除用户
    @DeleteMapping("/deleteUser/{id}")
    public Result deleteUser(@PathVariable("id") Integer id){
        return userService.deleteUser(id);
    }
    //更新用户
    @PutMapping("/updateUser/{id}")
    public Result updateUser(@PathVariable("id") Integer id,@RequestBody User user){
        return userService.updateUser(user,id);
    }

    //通过id来查询到用户回显
    @GetMapping("/getSingleUserById/{id}")
    public Result getSingleUserById(@PathVariable("id") Integer id){
        return userService.selectSingleUserById(id);
    }

    //通过学号查询用户
    @GetMapping("/getSingleUserByXue/{stuID}")
    public Result getSingleUserByXue(@PathVariable("stuID") String stuID){
        return userService.selectSingleUserByStuID(stuID);
    }


    //查询所有学生成绩
    @GetMapping("/getAllScore/{currentPage}/{size}")
    public Result getAllScore(@PathVariable("currentPage") Integer currentPage,@PathVariable("size") Integer size){
        return userService.selectAllScore(currentPage,size);
    }

   //通过学号查到学生成绩
    @GetMapping("/getScoreXue/{stuID}")
    public Result getScoreXue(@PathVariable("stuID") String stuID){
        return userService.selectSingleScoreByStuID(stuID);
    }
}
